package com.hebeu;

import java.sql.*;

public class JDBCdemo1 {
    public static void main(String[] args) throws Exception{
        //1.注册驱动
        DriverManager.registerDriver(new com.mysql.jdbc.Driver());
        //Class.forName("com.mysql.jdbc.driver");
        //2.连接数据库,获取连接
        Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","1705640");
        //3.获取预处理对象
        PreparedStatement pstm=conn.prepareStatement("select * from user");
        //4.操作数据库,得到结果集
        ResultSet rs= pstm.executeQuery();
        //5.遍历结果集
        while (rs.next()){
            System.out.println(rs.getString("username"));
        }
        //6.释放资源
        rs.close();
        pstm.close();
        conn.close();

    }
}
